//
//  MessageListTableViewCell.m
//  Learn
//
//  Created by zyl on 2024/4/3.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "MessageListTableViewCell.h"

@implementation MessageListTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.subTitleLabel];
    [self.contentView addSubview:self.coverImg];
    [self.coverImg addSubview:self.potLabel];
    [self.contentView addSubview:self.dateLabel];
    self.contentView.backgroundColor = lClearColor;
    self.backgroundColor = lClearColor;
    return self;
}
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.frame = CGRectMake(64,10,64,20);
        _titleLabel.font = MFontWithSize(16);
        _titleLabel.textColor = rgba(51, 51, 51, 1);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.text = @"惠州初中英语";
    
    }
    return _titleLabel;
}
- (UILabel *)subTitleLabel
{
    if (!_subTitleLabel) {
        
        _subTitleLabel = [[UILabel alloc] init];
        _subTitleLabel.frame = CGRectMake(64,16 + 20 + 6,lScreenWidth - 10 - 64,18);
        _subTitleLabel.font = RFontWithSize(12);
        _subTitleLabel.textColor = rgba(142, 142, 142, 1);
        _subTitleLabel.textAlignment = NSTextAlignmentLeft;
        _subTitleLabel.text = @"惠州初中英语";
    
    }
    return _subTitleLabel;
}
- (UILabel *)potLabel
{
    if (!_potLabel) {
        
        _potLabel = [[UILabel alloc] init];
        _potLabel.frame = CGRectMake(64,9,16,16);
        _potLabel.font = MFontWithSize(10);
        _potLabel.textColor = lWhiteColor;
        _potLabel.backgroundColor = rgba(250, 25, 44, 1);
        _potLabel.textAlignment = NSTextAlignmentCenter;
        _potLabel.text = @"19";
        [_potLabel setAllCornersWithCornerRadius:8];
        _potLabel.layer.borderColor = lWhiteColor.CGColor;
        _potLabel.layer.borderWidth = 1;
    
    }
    return _potLabel;
}
- (UILabel *)dateLabel
{
    if (!_dateLabel) {
        
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.frame = CGRectMake(138,17,lScreenWidth - 10 - 138,18);
        _dateLabel.font = RFontWithSize(14);
        _dateLabel.textColor = rgba(142, 142, 142, 1);
        _dateLabel.textAlignment = NSTextAlignmentRight;
        _dateLabel.text = @"惠州初中英语";
    
    }
    return _dateLabel;
}
- (UIImageView *)coverImg
{
    if (!_coverImg) {
        _coverImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 16, 44, 44)];
      //  _coverImg.backgroundColor = lRedColor;
       
    }
    return _coverImg;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setData:(NSDictionary *)data
{
    _data = data;
    //    if (arr1.count) {
    //        NSDictionary *dic = arr1.firstObject;
    //        [dic1 setObject:dic[@"create_time_text"] forKey:@"date"];
    //    }
    //
    //    [dic1 setObject:[NSNumber numberWithInt:[dic[@"data"][@"message_not_read"] intValue]] forKey:@"msg_number"];
    //    [dic1 setObject:dic[@"data"][@"message"] forKey:@"msg_list"];
    //    [dic1 setObject:@"ic_message_msg" forKey:@"icon"];
    self.coverImg.image = IMAGENAMED(data[@"icon"]);
    int n = [data[@"msg_number"] intValue];
    n = n > 99? 99:n;
    self.potLabel.hidden = n == 0;
    self.subTitleLabel.text = data[@"content"];
    self.potLabel.text = IntToStr(n);
    double width = [MethodTool getTextWidthWithStr:self.potLabel.text font:self.potLabel.font ViewHeight:self.potLabel.height] + 10;
    width = width < 16? 16:width;
    self.potLabel.width = width;
    self.titleLabel.text = data[@"title"];
    self.potLabel.centerX = self.coverImg.width;
    self.potLabel.centerY = 0;
    self.dateLabel.text = [MethodTool dateToStyle1WithDate:[data[@"date"] doubleValue]];
}
@end
